package com.epcs.controller.action;

import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts2.dispatcher.SessionMap;
import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.SessionAware;

import com.epcs.model.bo.UserBO;
import com.epcs.model.dto.Account;
import com.opensymphony.xwork2.ActionSupport;

public class ManageUserAction extends ActionSupport implements SessionAware,
		ServletRequestAware {
	private SessionMap<String, Object> sessionMap;
	private HttpServletRequest request;
	private String isActive;
	private String username;
    public String showUserList(){
    	String result = "Success";
    	UserBO userBO = new UserBO();
    	Account account = (Account) sessionMap.get("USER_INFO");
    	List<Account> listAccount = userBO.getAllAccount();
    	request.setAttribute("LIST_ACCOUNT", listAccount);
    	return result;
    }
    public String activeAccount(){
    	UserBO userBO = new UserBO();
    	String result = "Success";
    	System.out.println(isActive);
    	if("true".equals(isActive)){
    		Account user = userBO.getAccountByUsername(username);
    		user.setIsActive(false);
    		userBO.updateAccount(user);
    	}else{
    		Account user = userBO.getAccountByUsername(username);
    		user.setIsActive(true);
    		userBO.updateAccount(user);
    	}
    	
    	return result;
    }
	
	//------------------getter & setter--------------//
    public String getIsActive() {
		return isActive;
	}
	public void setIsActive(String isActive) {
		this.isActive = isActive;
	}
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
    
	// ---------------- session --------------------//

	@Override
	public void setSession(Map<String, Object> sessionMap) {
		this.sessionMap = (SessionMap<String, Object>) sessionMap;
	}

	
	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.request = request;

	}

}
